﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Hermes.Web.Orders
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					long ID=(Convert.ToInt64(Request.Params["id"]));
					ShowInfo(ID);
				}
			}
		}
			
	private void ShowInfo(long ID)
	{
		Hermes.BLL.Orders bll=new Hermes.BLL.Orders();
		Hermes.Model.Orders model=bll.GetModel(ID);
		this.lblID.Text=model.ID.ToString();
		this.txtOrderNumber.Text=model.OrderNumber;
		this.txtStatus.Text=model.Status.ToString();
		this.txtOrderTime.Text=model.OrderTime.ToString();
		this.txtAmount.Text=model.Amount.ToString();
		this.txtSiteID.Text=model.SiteID.ToString();
		this.txtAddTime.Text=model.AddTime.ToString();
		this.txtContact.Text=model.Contact;
		this.txtCompany.Text=model.Company;
		this.txtStreet.Text=model.Street;
		this.txtCity.Text=model.City;
		this.txtProvince.Text=model.Province;
		this.txtCountry.Text=model.Country;
		this.txtCountryCode.Text=model.CountryCode;
		this.txtPostcode.Text=model.Postcode;
		this.txtPhone.Text=model.Phone;
		this.txtEmail.Text=model.Email;
		this.txtTrackCode.Text=model.TrackCode;
		this.txtModifyOn.Text=model.ModifyOn.ToString();
		this.txtShippingMethod.Text=model.ShippingMethod.ToString();
		this.txtStoreID.Text=model.StoreID.ToString();
		this.txtShippingOn.Text=model.ShippingOn.ToString();
		this.txtShippingBy.Text=model.ShippingBy;
		this.txtImportOn.Text=model.ImportOn.ToString();
		this.txtImportBy.Text=model.ImportBy;
		this.txtLastUpdate.Text=model.LastUpdate.ToString();
		this.txtCustomerID.Text=model.CustomerID.ToString();
		this.txtPickUpAddressID.Text=model.PickUpAddressID.ToString();
		this.txtShipFromAddressID.Text=model.ShipFromAddressID.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtOrderNumber.Text.Trim().Length==0)
			{
				strErr+="OrderNumber不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtStatus.Text))
			{
				strErr+="Status格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtOrderTime.Text))
			{
				strErr+="OrderTime格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtAmount.Text))
			{
				strErr+="Amount格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtSiteID.Text))
			{
				strErr+="SiteID格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtAddTime.Text))
			{
				strErr+="AddTime格式错误！\\n";	
			}
			if(this.txtContact.Text.Trim().Length==0)
			{
				strErr+="Contact不能为空！\\n";	
			}
			if(this.txtCompany.Text.Trim().Length==0)
			{
				strErr+="Company不能为空！\\n";	
			}
			if(this.txtStreet.Text.Trim().Length==0)
			{
				strErr+="Street不能为空！\\n";	
			}
			if(this.txtCity.Text.Trim().Length==0)
			{
				strErr+="City不能为空！\\n";	
			}
			if(this.txtProvince.Text.Trim().Length==0)
			{
				strErr+="Province不能为空！\\n";	
			}
			if(this.txtCountry.Text.Trim().Length==0)
			{
				strErr+="Country不能为空！\\n";	
			}
			if(this.txtCountryCode.Text.Trim().Length==0)
			{
				strErr+="CountryCode不能为空！\\n";	
			}
			if(this.txtPostcode.Text.Trim().Length==0)
			{
				strErr+="Postcode不能为空！\\n";	
			}
			if(this.txtPhone.Text.Trim().Length==0)
			{
				strErr+="Phone不能为空！\\n";	
			}
			if(this.txtEmail.Text.Trim().Length==0)
			{
				strErr+="Email不能为空！\\n";	
			}
			if(this.txtTrackCode.Text.Trim().Length==0)
			{
				strErr+="TrackCode不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtModifyOn.Text))
			{
				strErr+="ModifyOn格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtShippingMethod.Text))
			{
				strErr+="ShippingMethod格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtStoreID.Text))
			{
				strErr+="StoreID格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtShippingOn.Text))
			{
				strErr+="ShippingOn格式错误！\\n";	
			}
			if(this.txtShippingBy.Text.Trim().Length==0)
			{
				strErr+="ShippingBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtImportOn.Text))
			{
				strErr+="ImportOn格式错误！\\n";	
			}
			if(this.txtImportBy.Text.Trim().Length==0)
			{
				strErr+="ImportBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtLastUpdate.Text))
			{
				strErr+="LastUpdate格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtCustomerID.Text))
			{
				strErr+="CustomerID格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtPickUpAddressID.Text))
			{
				strErr+="PickUpAddressID格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtShipFromAddressID.Text))
			{
				strErr+="ShipFromAddressID格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			long ID=long.Parse(this.lblID.Text);
			string OrderNumber=this.txtOrderNumber.Text;
			int Status=int.Parse(this.txtStatus.Text);
			DateTime OrderTime=DateTime.Parse(this.txtOrderTime.Text);
			decimal Amount=decimal.Parse(this.txtAmount.Text);
			int SiteID=int.Parse(this.txtSiteID.Text);
			DateTime AddTime=DateTime.Parse(this.txtAddTime.Text);
			string Contact=this.txtContact.Text;
			string Company=this.txtCompany.Text;
			string Street=this.txtStreet.Text;
			string City=this.txtCity.Text;
			string Province=this.txtProvince.Text;
			string Country=this.txtCountry.Text;
			string CountryCode=this.txtCountryCode.Text;
			string Postcode=this.txtPostcode.Text;
			string Phone=this.txtPhone.Text;
			string Email=this.txtEmail.Text;
			string TrackCode=this.txtTrackCode.Text;
			DateTime ModifyOn=DateTime.Parse(this.txtModifyOn.Text);
			int ShippingMethod=int.Parse(this.txtShippingMethod.Text);
			int StoreID=int.Parse(this.txtStoreID.Text);
			DateTime ShippingOn=DateTime.Parse(this.txtShippingOn.Text);
			string ShippingBy=this.txtShippingBy.Text;
			DateTime ImportOn=DateTime.Parse(this.txtImportOn.Text);
			string ImportBy=this.txtImportBy.Text;
			DateTime LastUpdate=DateTime.Parse(this.txtLastUpdate.Text);
			int CustomerID=int.Parse(this.txtCustomerID.Text);
			int PickUpAddressID=int.Parse(this.txtPickUpAddressID.Text);
			int ShipFromAddressID=int.Parse(this.txtShipFromAddressID.Text);


			Hermes.Model.Orders model=new Hermes.Model.Orders();
			model.ID=ID;
			model.OrderNumber=OrderNumber;
			model.Status=Status;
			model.OrderTime=OrderTime;
			model.Amount=Amount;
			model.SiteID=SiteID;
			model.AddTime=AddTime;
			model.Contact=Contact;
			model.Company=Company;
			model.Street=Street;
			model.City=City;
			model.Province=Province;
			model.Country=Country;
			model.CountryCode=CountryCode;
			model.Postcode=Postcode;
			model.Phone=Phone;
			model.Email=Email;
			model.TrackCode=TrackCode;
			model.ModifyOn=ModifyOn;
			model.ShippingMethod=ShippingMethod;
			model.StoreID=StoreID;
			model.ShippingOn=ShippingOn;
			model.ShippingBy=ShippingBy;
			model.ImportOn=ImportOn;
			model.ImportBy=ImportBy;
			model.LastUpdate=LastUpdate;
			model.CustomerID=CustomerID;
			model.PickUpAddressID=PickUpAddressID;
			model.ShipFromAddressID=ShipFromAddressID;

			Hermes.BLL.Orders bll=new Hermes.BLL.Orders();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
